package com.szh.zx.gaoDingJavaBook.chapter8.one;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

public class IteartorErrorTest {
	public static void main(String[] args) {
		Collection books = new HashSet();
		books.add("轻量级javaee企业级应用实战");
		books.add("疯狂java讲义");
		books.add("疯狂android讲义");
		Iterator iterator = books.iterator();
		while (iterator.hasNext()) {
			String book = (String) iterator.next();
			System.out.println(book);
			if (book.equals("疯狂java讲义")) {
//				使用Iterator 迭代过程中,不可修改集合元素，下面袋面引发异常
				try {
					books.remove(book);
				} catch (Exception e) {
					System.out.println(e.getMessage());
				}
			}
		}
	}
}
